#include "StdAfx.h"
#include "TextFile.h"

CTextFile::CTextFile(void)
{
}

CTextFile::~CTextFile(void)
{
}
BOOL CTextFile::ReadString(CString& rString) 
{
#ifdef _UNICODE
	if (GetPosition() == 0) 
	{
		Seek(2, CFile::begin);
	}
#endif  
	TCHAR tc;
	BOOL bFlag = false;

	rString.Empty();
	while (CFile::Read(&tc, sizeof(TCHAR))) 
	{
		switch (tc) 
		{
		case 0x0D: break;
		case 0x0A:
			bFlag = true;
			break;
		default:
			rString += tc;
	}

	if (bFlag)
		break;
	}
	return (!bFlag && rString.IsEmpty()) ? false : true;
}

void CTextFile::WriteString(LPCTSTR lpsz) 
{
	#ifdef _UNICODE
	if (GetPosition() == 0) 
	{
		char  tc[2];
		tc[0] = (char)0xFF;
		tc[1] = (char)0xFE;
		CFile::Write(tc, 2);
	}
	#endif
	//USES_CONVERSION;
	//W2A(lpsz);
	CFile::Write(lpsz,(UINT)(_tcslen(lpsz) * sizeof(TCHAR)));

}